
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#pragma once
#include "RTTypes.h"

#include <iostream>
using std::ostream;

namespace RT
{
	class RTComplex
	{
		public:
			/*Real part*/
			F64 m_r;

			/*Imaginary part*/
			F64 m_i; 

			/*Default constructor*/
			RTComplex();

			/*Constructor*/
			RTComplex(F64 real, F64 ima);

			/*Add operator*/
			RTComplex operator+ (const RTComplex& c)const;

			/*Minus operator*/
			RTComplex operator- (const RTComplex& c)const;

			/*Minus operator*/
			RTComplex operator- (F64 f)const;

			/*Unary minus operator*/
			RTComplex operator- ()const;

			/*Multiplication operator*/
			RTComplex operator* (const RTComplex& c)const;

			/*Multiplication with float*/
			RTComplex operator* (F64 f)const;

			/*Division with float*/
			RTComplex operator/ (F64 f)const;

			/*Division*/
			RTComplex operator/ (const RTComplex& c)const;

			/*Divide and assign*/
			void operator/= (F64 f);

			/*Multiply and assign*/
			void operator*= (const RTComplex& c);

			/*Add an assign*/
			void operator+= (const RTComplex& c);

			/*Equal operator*/
			bool operator==(const RTComplex& c)const;

			/*Equal operator*/
			bool operator==(F32 f)const;

			/*Return the modulus*/
			F64 modulus()const;

			/*Return the squared modulus*/
			F64 modulus2()const;

			/*Return the square root of the complex number*/
			RTComplex squareRoot()const;

			/*Return the conjugate*/
			RTComplex conjugate()const;

			/*Return the inverse*/
			RTComplex inverse()const;

			/*Check if the complex number is a real number*/
			bool isReal()const;

	};

	/*Return a stream with the values of the complex number*/
	ostream& operator<<(ostream& s, const RTComplex& c);
}